package com.xlh.support.training.dao.helper;

import com.xlh.support.training.dao.TrainingMapper;
import com.xlh.support.training.domain.Training;
import com.xlh.support.training.domain.example.TrainingExample;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cheer
 */
@Repository
public class TrainingMapperHelper {

    @Autowired
    private TrainingMapper trainingMapper;

    public Training getById(Long id) {
        Training training = trainingMapper.selectByPrimaryKey(id);
        if (training == null || training.getDeleted()) {
            return null;
        }
        return training;
    }

    public Boolean isExistsTrainingName(String trainingName) {
        TrainingExample example = new TrainingExample();
        example.or().andTrainingNameEqualTo(trainingName)
                .andDeletedEqualTo(false);
        List<Training> trainings = trainingMapper.selectByExample(example);
        return CollectionUtils.isNotEmpty(trainings);
    }
}
